package com.zhuky.task;

import java.util.concurrent.Future;

import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

@Component
public class TestAsyncTask {

	@Async
	public Future<Boolean> doTask1() throws InterruptedException{
		long start = System.currentTimeMillis();
		Thread.sleep(1000);
		long end = System.currentTimeMillis();
		System.out.println("任务1耗时:"+ (end-start) + "毫秒");
		return new AsyncResult<Boolean>(true);
	}

	@Async
	public Future<Boolean> doTask2() throws InterruptedException{
		long start = System.currentTimeMillis();
		Thread.sleep(700);
		long end = System.currentTimeMillis();
		System.out.println("任务2耗时:"+ (end-start) + "毫秒");
		return new AsyncResult<Boolean>(true);
	}

	@Async
	public Future<Boolean> doTask3() throws InterruptedException{
		long start = System.currentTimeMillis();
		Thread.sleep(600);
		long end = System.currentTimeMillis();
		System.out.println("任务3耗时:"+ (end-start) + "毫秒");
		return new AsyncResult<Boolean>(true);
	}
	
}
